# Docker 构建和部署脚本

Write-Host "开始构建 Docker 镜像..." -ForegroundColor Green

# 检查 .env 文件
if (-not (Test-Path .env)) {
    Write-Host "错误: .env 文件不存在，请先创建并配置 API Key" -ForegroundColor Red
    exit 1
}

# 构建后端镜像
Write-Host "`n[1/2] 构建后端镜像..." -ForegroundColor Yellow
docker build -f Dockerfile.backend -t housailei-backend:latest .

if ($LASTEXITCODE -ne 0) {
    Write-Host "后端镜像构建失败！" -ForegroundColor Red
    Write-Host "提示: 如果无法连接 Docker Hub，请配置镜像源" -ForegroundColor Yellow
    exit 1
}

# 构建前端镜像
Write-Host "`n[2/2] 构建前端镜像..." -ForegroundColor Yellow
docker build -f housailei-bot-001-web/Dockerfile.frontend -t housailei-frontend:latest ./housailei-bot-001-web

if ($LASTEXITCODE -ne 0) {
    Write-Host "前端镜像构建失败！" -ForegroundColor Red
    exit 1
}

Write-Host "`n镜像构建完成！" -ForegroundColor Green

# 启动服务
Write-Host "`n启动服务..." -ForegroundColor Green
docker compose up -d

if ($LASTEXITCODE -eq 0) {
    Write-Host "`n部署成功！" -ForegroundColor Green
    Write-Host "前端地址: http://localhost:8000" -ForegroundColor Cyan
    Write-Host "后端地址: http://localhost:8081" -ForegroundColor Cyan
    Write-Host "API 文档: http://localhost:8081/swagger-ui.html" -ForegroundColor Cyan
    Write-Host "`n查看日志: docker compose logs -f" -ForegroundColor Yellow
} else {
    Write-Host "服务启动失败！" -ForegroundColor Red
    Write-Host "查看日志: docker compose logs" -ForegroundColor Yellow
}

